# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 下午5:21
# @Author  : liujun
# @Email   : 2592730854@qq.com
# @File    : knowledge_add_page.py
# @Software: PyCharm


from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select

class  KnowledgeAddPage(BasePage):
    """添加知识页面"""
    url="/crm/index.php?m=knowledge&a=add"

    title_locator = (By.ID, "title")  # 标题
    # 分类框
    sort_locator = (By.CSS_SELECTOR,
                    "body > div.container > div.row > div > form > table > tbody > tr:nth-child(3) > td:nth-child(2) > select")
    content_locator = (By.CSS_SELECTOR, "body")  # 内容
    save_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td/input[1]")  # 保存


    def sort(self,class_name):
        """分类框"""
        sort_element = self.driver.find_element(*self.sort_locator)
        sort_obj = Select(sort_element)
        sort_obj.select_by_visible_text(class_name)


    def input_title(self,title):
        """输入标题"""
        self.driver.find_element(*self.title_locator).send_keys(title)
    def switch_default_frame(self):
        """切换到最外层frame"""
        self.driver.switch_to.default_content()
    def switch_own_frame(self):
        """切换到自己所在的frame"""
        self.driver.switch_to.frame(0)
    def input_content(self,content):
        """输入内容"""
        self.driver.find_element(*self.content_locator).send_keys(content)
    def click_save(self):
        """点击保存"""
        self.driver.find_element(*self.save_locator).click()

